<?php
	/**
	 * This is a MetaControl class, providing a QForm or QPanel access to event handlers
	 * and QControls to perform the Create, Edit, and Delete functionality
	 * of the TableProjectEdit class.  This code-generated class
	 * contains all the basic elements to help a QPanel or QForm display an HTML form that can
	 * manipulate a single TableProjectEdit object.
	 *
	 * To take advantage of some (or all) of these control objects, you
	 * must create a new QForm or QPanel which instantiates a TableProjectEditMetaControl
	 * class.
	 *
	 * Any and all changes to this file will be overwritten with any subsequent
	 * code re-generation.
	 * 
	 * @package My Application
	 * @subpackage MetaControls
	 * property-read TableProjectEdit $TableProjectEdit the actual TableProjectEdit data class being edited
	 * property QLabel $IdControl
	 * property-read QLabel $IdLabel
	 * property QListBox $ProjectIdControl
	 * property-read QLabel $ProjectIdLabel
	 * property QListBox $UserIdControl
	 * property-read QLabel $UserIdLabel
	 * property QDateTimePicker $MessageDateControl
	 * property-read QLabel $MessageDateLabel
	 * property QTextBox $MessageControl
	 * property-read QLabel $MessageLabel
	 * property QIntegerTextBox $StatusControl
	 * property-read QLabel $StatusLabel
	 * property-read string $TitleVerb a verb indicating whether or not this is being edited or created
	 * property-read boolean $EditMode a boolean indicating whether or not this is being edited or created
	 */

	class TableProjectEditMetaControlGen extends QBaseClass {
		// General Variables
		protected $objTableProjectEdit;
		protected $objParentObject;
		protected $strTitleVerb;
		protected $blnEditMode;

		// Controls that allow the editing of TableProjectEdit's individual data fields
		protected $lblId;
		protected $lstProject;
		protected $lstUser;
		protected $calMessageDate;
		protected $txtMessage;
		protected $txtStatus;

		// Controls that allow the viewing of TableProjectEdit's individual data fields
		protected $lblProjectId;
		protected $lblUserId;
		protected $lblMessageDate;
		protected $lblMessage;
		protected $lblStatus;

		// QListBox Controls (if applicable) to edit Unique ReverseReferences and ManyToMany References

		// QLabel Controls (if applicable) to view Unique ReverseReferences and ManyToMany References


		/**
		 * Main constructor.  Constructor OR static create methods are designed to be called in either
		 * a parent QPanel or the main QForm when wanting to create a
		 * TableProjectEditMetaControl to edit a single TableProjectEdit object within the
		 * QPanel or QForm.
		 *
		 * This constructor takes in a single TableProjectEdit object, while any of the static
		 * create methods below can be used to construct based off of individual PK ID(s).
		 *
		 * @param mixed $objParentObject QForm or QPanel which will be using this TableProjectEditMetaControl
		 * @param TableProjectEdit $objTableProjectEdit new or existing TableProjectEdit object
		 */
		 public function __construct($objParentObject, TableProjectEdit $objTableProjectEdit) {
			// Setup Parent Object (e.g. QForm or QPanel which will be using this TableProjectEditMetaControl)
			$this->objParentObject = $objParentObject;

			// Setup linked TableProjectEdit object
			$this->objTableProjectEdit = $objTableProjectEdit;

			// Figure out if we're Editing or Creating New
			if ($this->objTableProjectEdit->__Restored) {
				$this->strTitleVerb = QApplication::Translate('Edit');
				$this->blnEditMode = true;
			} else {
				$this->strTitleVerb = QApplication::Translate('Create');
				$this->blnEditMode = false;
			}
		 }

		/**
		 * Static Helper Method to Create using PK arguments
		 * You must pass in the PK arguments on an object to load, or leave it blank to create a new one.
		 * If you want to load via QueryString or PathInfo, use the CreateFromQueryString or CreateFromPathInfo
		 * static helper methods.  Finally, specify a CreateType to define whether or not we are only allowed to 
		 * edit, or if we are also allowed to create a new one, etc.
		 * 
		 * @param mixed $objParentObject QForm or QPanel which will be using this TableProjectEditMetaControl
		 * @param integer $intId primary key value
		 * @param QMetaControlCreateType $intCreateType rules governing TableProjectEdit object creation - defaults to CreateOrEdit
 		 * @return TableProjectEditMetaControl
		 */
		public static function Create($objParentObject, $intId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
			// Attempt to Load from PK Arguments
			if (strlen($intId)) {
				$objTableProjectEdit = TableProjectEdit::Load($intId);

				// TableProjectEdit was found -- return it!
				if ($objTableProjectEdit)
					return new TableProjectEditMetaControl($objParentObject, $objTableProjectEdit);

				// If CreateOnRecordNotFound not specified, throw an exception
				else if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound)
					throw new QCallerException('Could not find a TableProjectEdit object with PK arguments: ' . $intId);

			// If EditOnly is specified, throw an exception
			} else if ($intCreateType == QMetaControlCreateType::EditOnly)
				throw new QCallerException('No PK arguments specified');

			// If we are here, then we need to create a new record
			return new TableProjectEditMetaControl($objParentObject, new TableProjectEdit());
		}

		/**
		 * Static Helper Method to Create using PathInfo arguments
		 *
		 * @param mixed $objParentObject QForm or QPanel which will be using this TableProjectEditMetaControl
		 * @param QMetaControlCreateType $intCreateType rules governing TableProjectEdit object creation - defaults to CreateOrEdit
		 * @return TableProjectEditMetaControl
		 */
		public static function CreateFromPathInfo($objParentObject, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
			$intId = QApplication::PathInfo(0);
			return TableProjectEditMetaControl::Create($objParentObject, $intId, $intCreateType);
		}

		/**
		 * Static Helper Method to Create using QueryString arguments
		 *
		 * @param mixed $objParentObject QForm or QPanel which will be using this TableProjectEditMetaControl
		 * @param QMetaControlCreateType $intCreateType rules governing TableProjectEdit object creation - defaults to CreateOrEdit
		 * @return TableProjectEditMetaControl
		 */
		public static function CreateFromQueryString($objParentObject, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
			$intId = QApplication::QueryString('intId');
			return TableProjectEditMetaControl::Create($objParentObject, $intId, $intCreateType);
		}



		///////////////////////////////////////////////
		// PUBLIC CREATE and REFRESH METHODS
		///////////////////////////////////////////////

		/**
		 * Create and setup QLabel lblId
		 * @param string $strControlId optional ControlId to use
		 * @return QLabel
		 */
		public function lblId_Create($strControlId = null) {
			$this->lblId = new QLabel($this->objParentObject, $strControlId);
			$this->lblId->Name = QApplication::Translate('Id');
			if ($this->blnEditMode)
				$this->lblId->Text = $this->objTableProjectEdit->Id;
			else
				$this->lblId->Text = 'N/A';
			return $this->lblId;
		}

		/**
		 * Create and setup QListBox lstProject
		 * @param string $strControlId optional ControlId to use
		 * @return QListBox
		 */
		public function lstProject_Create($strControlId = null) {
			$this->lstProject = new QListBox($this->objParentObject, $strControlId);
			$this->lstProject->Name = QApplication::Translate('Project');
			$this->lstProject->Required = true;
			if (!$this->blnEditMode)
				$this->lstProject->AddItem(QApplication::Translate('- Select One -'), null);
			$objProjectArray = TableProject::LoadAll();
			if ($objProjectArray) foreach ($objProjectArray as $objProject) {
				$objListItem = new QListItem($objProject->__toString(), $objProject->Id);
				if (($this->objTableProjectEdit->Project) && ($this->objTableProjectEdit->Project->Id == $objProject->Id))
					$objListItem->Selected = true;
				$this->lstProject->AddItem($objListItem);
			}
			return $this->lstProject;
		}

		/**
		 * Create and setup QLabel lblProjectId
		 * @param string $strControlId optional ControlId to use
		 * @return QLabel
		 */
		public function lblProjectId_Create($strControlId = null) {
			$this->lblProjectId = new QLabel($this->objParentObject, $strControlId);
			$this->lblProjectId->Name = QApplication::Translate('Project');
			$this->lblProjectId->Text = ($this->objTableProjectEdit->Project) ? $this->objTableProjectEdit->Project->__toString() : null;
			$this->lblProjectId->Required = true;
			return $this->lblProjectId;
		}

		/**
		 * Create and setup QListBox lstUser
		 * @param string $strControlId optional ControlId to use
		 * @return QListBox
		 */
		public function lstUser_Create($strControlId = null) {
			$this->lstUser = new QListBox($this->objParentObject, $strControlId);
			$this->lstUser->Name = QApplication::Translate('User');
			$this->lstUser->Required = true;
			if (!$this->blnEditMode)
				$this->lstUser->AddItem(QApplication::Translate('- Select One -'), null);
			$objUserArray = TableUserProject::LoadAll();
			if ($objUserArray) foreach ($objUserArray as $objUser) {
				$objListItem = new QListItem($objUser->__toString(), $objUser->Id);
				if (($this->objTableProjectEdit->User) && ($this->objTableProjectEdit->User->Id == $objUser->Id))
					$objListItem->Selected = true;
				$this->lstUser->AddItem($objListItem);
			}
			return $this->lstUser;
		}

		/**
		 * Create and setup QLabel lblUserId
		 * @param string $strControlId optional ControlId to use
		 * @return QLabel
		 */
		public function lblUserId_Create($strControlId = null) {
			$this->lblUserId = new QLabel($this->objParentObject, $strControlId);
			$this->lblUserId->Name = QApplication::Translate('User');
			$this->lblUserId->Text = ($this->objTableProjectEdit->User) ? $this->objTableProjectEdit->User->__toString() : null;
			$this->lblUserId->Required = true;
			return $this->lblUserId;
		}

		/**
		 * Create and setup QDateTimePicker calMessageDate
		 * @param string $strControlId optional ControlId to use
		 * @return QDateTimePicker
		 */
		public function calMessageDate_Create($strControlId = null) {
			$this->calMessageDate = new QDateTimePicker($this->objParentObject, $strControlId);
			$this->calMessageDate->Name = QApplication::Translate('Message Date');
			$this->calMessageDate->DateTime = $this->objTableProjectEdit->MessageDate;
			$this->calMessageDate->DateTimePickerType = QDateTimePickerType::DateTime;
			return $this->calMessageDate;
		}

		/**
		 * Create and setup QLabel lblMessageDate
		 * @param string $strControlId optional ControlId to use
		 * @param string $strDateTimeFormat optional DateTimeFormat to use
		 * @return QLabel
		 */
		public function lblMessageDate_Create($strControlId = null, $strDateTimeFormat = null) {
			$this->lblMessageDate = new QLabel($this->objParentObject, $strControlId);
			$this->lblMessageDate->Name = QApplication::Translate('Message Date');
			$this->strMessageDateDateTimeFormat = $strDateTimeFormat;
			$this->lblMessageDate->Text = sprintf($this->objTableProjectEdit->MessageDate) ? $this->objTableProjectEdit->MessageDate->__toString($this->strMessageDateDateTimeFormat) : null;
			return $this->lblMessageDate;
		}

		protected $strMessageDateDateTimeFormat;


		/**
		 * Create and setup QTextBox txtMessage
		 * @param string $strControlId optional ControlId to use
		 * @return QTextBox
		 */
		public function txtMessage_Create($strControlId = null) {
			$this->txtMessage = new QTextBox($this->objParentObject, $strControlId);
			$this->txtMessage->Name = QApplication::Translate('Message');
			$this->txtMessage->Text = $this->objTableProjectEdit->Message;
			$this->txtMessage->TextMode = QTextMode::MultiLine;
			return $this->txtMessage;
		}

		/**
		 * Create and setup QLabel lblMessage
		 * @param string $strControlId optional ControlId to use
		 * @return QLabel
		 */
		public function lblMessage_Create($strControlId = null) {
			$this->lblMessage = new QLabel($this->objParentObject, $strControlId);
			$this->lblMessage->Name = QApplication::Translate('Message');
			$this->lblMessage->Text = $this->objTableProjectEdit->Message;
			return $this->lblMessage;
		}

		/**
		 * Create and setup QIntegerTextBox txtStatus
		 * @param string $strControlId optional ControlId to use
		 * @return QIntegerTextBox
		 */
		public function txtStatus_Create($strControlId = null) {
			$this->txtStatus = new QIntegerTextBox($this->objParentObject, $strControlId);
			$this->txtStatus->Name = QApplication::Translate('Status');
			$this->txtStatus->Text = $this->objTableProjectEdit->Status;
			$this->txtStatus->Required = true;
			return $this->txtStatus;
		}

		/**
		 * Create and setup QLabel lblStatus
		 * @param string $strControlId optional ControlId to use
		 * @param string $strFormat optional sprintf format to use
		 * @return QLabel
		 */
		public function lblStatus_Create($strControlId = null, $strFormat = null) {
			$this->lblStatus = new QLabel($this->objParentObject, $strControlId);
			$this->lblStatus->Name = QApplication::Translate('Status');
			$this->lblStatus->Text = $this->objTableProjectEdit->Status;
			$this->lblStatus->Required = true;
			$this->lblStatus->Format = $strFormat;
			return $this->lblStatus;
		}



		/**
		 * Refresh this MetaControl with Data from the local TableProjectEdit object.
		 * @param boolean $blnReload reload TableProjectEdit from the database
		 * @return void
		 */
		public function Refresh($blnReload = false) {
			if ($blnReload)
				$this->objTableProjectEdit->Reload();

			if ($this->lblId) if ($this->blnEditMode) $this->lblId->Text = $this->objTableProjectEdit->Id;

			if ($this->lstProject) {
					$this->lstProject->RemoveAllItems();
				if (!$this->blnEditMode)
					$this->lstProject->AddItem(QApplication::Translate('- Select One -'), null);
				$objProjectArray = TableProject::LoadAll();
				if ($objProjectArray) foreach ($objProjectArray as $objProject) {
					$objListItem = new QListItem($objProject->__toString(), $objProject->Id);
					if (($this->objTableProjectEdit->Project) && ($this->objTableProjectEdit->Project->Id == $objProject->Id))
						$objListItem->Selected = true;
					$this->lstProject->AddItem($objListItem);
				}
			}
			if ($this->lblProjectId) $this->lblProjectId->Text = ($this->objTableProjectEdit->Project) ? $this->objTableProjectEdit->Project->__toString() : null;

			if ($this->lstUser) {
					$this->lstUser->RemoveAllItems();
				if (!$this->blnEditMode)
					$this->lstUser->AddItem(QApplication::Translate('- Select One -'), null);
				$objUserArray = TableUserProject::LoadAll();
				if ($objUserArray) foreach ($objUserArray as $objUser) {
					$objListItem = new QListItem($objUser->__toString(), $objUser->Id);
					if (($this->objTableProjectEdit->User) && ($this->objTableProjectEdit->User->Id == $objUser->Id))
						$objListItem->Selected = true;
					$this->lstUser->AddItem($objListItem);
				}
			}
			if ($this->lblUserId) $this->lblUserId->Text = ($this->objTableProjectEdit->User) ? $this->objTableProjectEdit->User->__toString() : null;

			if ($this->calMessageDate) $this->calMessageDate->DateTime = $this->objTableProjectEdit->MessageDate;
			if ($this->lblMessageDate) $this->lblMessageDate->Text = sprintf($this->objTableProjectEdit->MessageDate) ? $this->objTableProjectEdit->MessageDate->__toString($this->strMessageDateDateTimeFormat) : null;

			if ($this->txtMessage) $this->txtMessage->Text = $this->objTableProjectEdit->Message;
			if ($this->lblMessage) $this->lblMessage->Text = $this->objTableProjectEdit->Message;

			if ($this->txtStatus) $this->txtStatus->Text = $this->objTableProjectEdit->Status;
			if ($this->lblStatus) $this->lblStatus->Text = $this->objTableProjectEdit->Status;

		}



		///////////////////////////////////////////////
		// PROTECTED UPDATE METHODS for ManyToManyReferences (if any)
		///////////////////////////////////////////////





		///////////////////////////////////////////////
		// PUBLIC TABLEPROJECTEDIT OBJECT MANIPULATORS
		///////////////////////////////////////////////

		/**
		 * This will save this object's TableProjectEdit instance,
		 * updating only the fields which have had a control created for it.
		 */
		public function SaveTableProjectEdit() {
			try {
				// Update any fields for controls that have been created
				if ($this->lstProject) $this->objTableProjectEdit->ProjectId = $this->lstProject->SelectedValue;
				if ($this->lstUser) $this->objTableProjectEdit->UserId = $this->lstUser->SelectedValue;
				if ($this->calMessageDate) $this->objTableProjectEdit->MessageDate = $this->calMessageDate->DateTime;
				if ($this->txtMessage) $this->objTableProjectEdit->Message = $this->txtMessage->Text;
				if ($this->txtStatus) $this->objTableProjectEdit->Status = $this->txtStatus->Text;

				// Update any UniqueReverseReferences (if any) for controls that have been created for it

				// Save the TableProjectEdit object
				$this->objTableProjectEdit->Save();

				// Finally, update any ManyToManyReferences (if any)
			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}
		}

		/**
		 * This will DELETE this object's TableProjectEdit instance from the database.
		 * It will also unassociate itself from any ManyToManyReferences.
		 */
		public function DeleteTableProjectEdit() {
			$this->objTableProjectEdit->Delete();
		}		



		///////////////////////////////////////////////
		// PUBLIC GETTERS and SETTERS
		///////////////////////////////////////////////

		/**
		 * Override method to perform a property "Get"
		 * This will get the value of $strName
		 *
		 * @param string $strName Name of the property to get
		 * @return mixed
		 */
		public function __get($strName) {
			switch ($strName) {
				// General MetaControlVariables
				case 'TableProjectEdit': return $this->objTableProjectEdit;
				case 'TitleVerb': return $this->strTitleVerb;
				case 'EditMode': return $this->blnEditMode;

				// Controls that point to TableProjectEdit fields -- will be created dynamically if not yet created
				case 'IdControl':
					if (!$this->lblId) return $this->lblId_Create();
					return $this->lblId;
				case 'IdLabel':
					if (!$this->lblId) return $this->lblId_Create();
					return $this->lblId;
				case 'ProjectIdControl':
					if (!$this->lstProject) return $this->lstProject_Create();
					return $this->lstProject;
				case 'ProjectIdLabel':
					if (!$this->lblProjectId) return $this->lblProjectId_Create();
					return $this->lblProjectId;
				case 'UserIdControl':
					if (!$this->lstUser) return $this->lstUser_Create();
					return $this->lstUser;
				case 'UserIdLabel':
					if (!$this->lblUserId) return $this->lblUserId_Create();
					return $this->lblUserId;
				case 'MessageDateControl':
					if (!$this->calMessageDate) return $this->calMessageDate_Create();
					return $this->calMessageDate;
				case 'MessageDateLabel':
					if (!$this->lblMessageDate) return $this->lblMessageDate_Create();
					return $this->lblMessageDate;
				case 'MessageControl':
					if (!$this->txtMessage) return $this->txtMessage_Create();
					return $this->txtMessage;
				case 'MessageLabel':
					if (!$this->lblMessage) return $this->lblMessage_Create();
					return $this->lblMessage;
				case 'StatusControl':
					if (!$this->txtStatus) return $this->txtStatus_Create();
					return $this->txtStatus;
				case 'StatusLabel':
					if (!$this->lblStatus) return $this->lblStatus_Create();
					return $this->lblStatus;
				default:
					try {
						return parent::__get($strName);
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}
			}
		}

		/**
		 * Override method to perform a property "Set"
		 * This will set the property $strName to be $mixValue
		 *
		 * @param string $strName Name of the property to set
		 * @param string $mixValue New value of the property
		 * @return mixed
		 */
		public function __set($strName, $mixValue) {
			try {
				switch ($strName) {
					// Controls that point to TableProjectEdit fields
					case 'IdControl':
						return ($this->lblId = QType::Cast($mixValue, 'QControl'));
					case 'ProjectIdControl':
						return ($this->lstProject = QType::Cast($mixValue, 'QControl'));
					case 'UserIdControl':
						return ($this->lstUser = QType::Cast($mixValue, 'QControl'));
					case 'MessageDateControl':
						return ($this->calMessageDate = QType::Cast($mixValue, 'QControl'));
					case 'MessageControl':
						return ($this->txtMessage = QType::Cast($mixValue, 'QControl'));
					case 'StatusControl':
						return ($this->txtStatus = QType::Cast($mixValue, 'QControl'));
					default:
						return parent::__set($strName, $mixValue);
				}
			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}
		}
	}
?>